
#include <cstdio>

#include <BDialog>
#include <BTextEdit>
#include <BVBoxLayout>
#include <BApplication>
#include <BReadWrite>

#include "HistoryDialog.h"
#include "ScriptStudio.h"

int main(int argc, char** argv)
{
	BApplication app(argc, argv);
	app.setFrequency(100);
	app.setCurrentPath(BString(argv[0]).path());
	app.setStyleSheet("data/style/script.css");

	BString fileName;
	if (argc > 1)
	{
		fileName = argv[1];
	}
	else
	{
		HistoryDialog* historyDialog = new HistoryDialog();
		if (!historyDialog->empty())
		{
			Button result = historyDialog->execute();
			if (result == Button_None)
				return 0;
			if (result == Button_Open)
				fileName = (const BString&)historyDialog->property("file");
		}
		app.setProperty("history-dialog", historyDialog);
	}

	ScriptStudio* studio = new ScriptStudio();
	//studio->setFrameless(true);
	studio->show();
	if (fileName.size())
	{
		studio->loadProject(fileName);
	}

	return app.execute();
}